from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d):
        super().__init__(d)

    def get_name(self):
        return "动物餐厅"

    def game_alert(self):
        self.alert_close_by_file('./game/img/动物餐厅')

    def handle_main(self):
        self.log_msg("等待进入游戏页面")
        self.img_exit("./game/img/动物餐厅/game_main.png", 100)
        self.log_msg("已进入游戏页面")
        self.game_alert()

        self.img_click_if_exists("开始领取小费", "./game/img/动物餐厅/prize.png", './game/img/动物餐厅/prize01.png')
        self.img_click("./game/img/动物餐厅/prize01.png")

        self.log_msg("找宣传位置")
        share_img = ''
        if self.img_exit("./game/img/动物餐厅/play01.png"):
            share_img = "./game/img/动物餐厅/play01.png"
        if self.img_exit("./game/img/动物餐厅/play02.png"):
            share_img = "./game/img/动物餐厅/play02.png"
        if share_img == '':
            self.log_msg("宣传位置，未找到")
            return False

        self.log_msg("开始帮客人点餐")
        while not self.check_done():
            self.d.sleep(2)
            while self.img_exit("./game/img/动物餐厅/play.png", 5):
                self.log_msg("有客人需要点餐", False)
                self.img_click("./game/img/动物餐厅/play.png")

            if self.img_exit("./game/img/动物餐厅/play_door.png", 2):
                self.log_msg("不小心出门了，点击回到餐厅")
                self.img_click("./game/img/动物餐厅/play_door.png")

            self.log_msg("点击60次宣传单")
            self.img_click(share_img, 10, 60)

        return True
